<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
include_once('../config/field.php');
$ColumnType = 2; //栏目类型:0栏目内容分类,1新闻分类,2产品分类
if($ps['cut']['common']) $ConfigProductPhoto1 = 0; //共用大小图、不显示小图上传域
$product_field = $customize_field['product']; //自定义字段
if(!is_array($product_field)) $product_field = array();
if($_POST['Action']=='Add'){
	$ConfigProductSecrecy == 1 ? $ProductSecrecy = $_POST['ProductSecrecy'] : $ProductSecrecy = 0;
	$ConfigProductNew == 1 ? $ProductNew = $_POST['ProductNew'] : $ProductNew = 0;
	$ConfigProductRecommended == 1 ? $ProductRecommended = $_POST['ProductRecommended'] : $ProductRecommended = 0;
	$ConfigProductAudit == 1 ? $ProductAudit = $_POST['ProductAudit'] : $ProductAudit = 1;
	$ConfigProductClick == 1 ? $ProductClick = $_POST['ProductClick'] : $ProductClick = 0;
	$ConfigProductSort == 1 ? $ProductSort = $_POST['ProductSort'] : $ProductSort = 0;
	$npics = picstreatment(1,'ProductPhoto1,ProductPhoto2');
	
	$sql_add1 = $sql_add2 = NULL;
	foreach($product_field as $i => $n){
		$sql_add1 .= ",`{$n[0]}`";
		$sql_add2 .= ",'" . trim($_POST[$n[0]]) . "'"; 
	}
	
	$SQL = "INSERT INTO `" . $dbprefix . "product` (`ProductLang`,`ProductRela`,`ProductName`,`ProductNameColor`,`ProductBrand`,`ProductModel`,`ProductCoding`,
	`ProductSpeci`,`ProductColor`,`ProductPrice`,`ProductKeyWord`,`ProductPhoto1`,`ProductPhoto2`,`ProductSummary`,`ProductContent`,`ProductSecrecy`,
	`ProductNew`,`ProductRecommended`,`ProductAudit`,`ProductClick`,`ProductSort`,`ProductPublished`,`ProductTime`{$sql_add1})VALUES (
	'$Lang','" . $_POST['ProductRela'] . "','" . $_POST['ProductName'] . "','" . $_POST['ProductNameColor'] . "','" . $_POST['ProductBrand'] . "',
	'" . $_POST['ProductModel'] . "','" . $_POST['ProductCoding'] . "','" . $_POST['ProductSpeci'] . "','" . $_POST['ProductColor'] . "',
	'" . $_POST['ProductPrice'] . "','" . $_POST['ProductKeyWord'] . "','" . $upURL1 . "','" . $upURL2 . "',
	'" . $_POST['ProductSummary'] . "','" . $_POST['ProductContent'] . "','$ProductSecrecy','$ProductNew','$ProductRecommended','$ProductAudit',
	'$ProductClick','$ProductSort','" . $_POST['ProductPublished'] . "',NOW(){$sql_add2});";
	unset($ProductSecrecy,$ProductNew,$ProductRecommended,$ProductAudit,$ProductClick,$ProductSort);
	if($ID = $db->ExecuteSQL($SQL,1)){
		AdminLog(2,$Lang,'添加产品，结果：操作成功！'); 
		if($npics !== true){
			MsgBox (1,"产品添加成功，图片上传失败，返回信息：{$npics}","ProductUpDate.php?Lang={$Lang}&ID={$ID}");
		}		
		if($_POST['isHTML'] == 'yes'){
			MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexProduct&StartID={$ID}&EndID={$ID}");
		}
		MsgBox (1,'操作成功！','ProductManage.php?Lang=' . $Lang);
	} else {
		AdminLog(2,$Lang,'添加产品，结果：操作失败！'); 
		MsgBox (1,'操作失败，请检查您提交的数据是否正确！','-1');
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加产品</title>
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script src="../tools/ckeditor/ckeditor.js" type="text/javascript"></script>
<script src="../js/jquery.js" type="text/javascript"></script>
<script language="javascript">
//标题文件颜色选择
var tempColor;
function returnColor(){
	var Hcolor = dlgHelper.ChooseColorDlg(tempColor).toString(16);
	with(event.srcElement){tempColor = ((Hcolor.length<6)?"000000".substring(0,6-Hcolor.length):"") + Hcolor;}	
	document.getElementById('SelectColor').style.backgroundColor = '#' + tempColor;
	document.getElementById('ProductNameColor').value = '#' + tempColor;
	document.getElementById('ProductName').style.color= '#' + tempColor;
}
function DelColor(){
	document.getElementById('SelectColor').style.backgroundColor = '#CCCCCC';
	document.getElementById('ProductNameColor').value = '';
	document.getElementById('ProductName').style.color= '#000000';
}
function trim(str) {
	return str.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g,"");
}
function FormCheck(){
	if(trim(document.form1.ProductRela.value)==""){
		alert('请选择产品类别！');
		document.form1.ProductRela.focus();
		return false;
	}
	if(trim(document.form1.ProductName.value)==""){
		alert('请填写产品名称！');
		document.form1.ProductName.focus();
		return false;
	}
	<?php if($ConfigProductClick==1){?>
	if(document.form1.ProductClick.value.match(/^[0-9]\d*$/)==null){ 
		alert("点击数必须为数字！"); 
		document.form1.ProductClick.focus(); 
		return false; 
	}
	<?php } if($ConfigProductSort==1){?>
	if(document.form1.ProductSort.value.match(/^[0-9]\d*$/)==null){ 
		alert("排序必须为数字！"); 
		document.form1.ProductSort.focus(); 
		return false; 
	}	
	<?php }?>
}
$(document).ready(function(){CKEDITOR.replace('ProductContent');});
</script>
</head>
<body>
<br />
<OBJECT id="dlgHelper" CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT> <!--Win拾色器-->
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd"><td><?php TopLang();?></td>
	<td align="right">
		<input type="button" value="产品管理" onClick="javascript:location.href='ProductManage.php?Lang=<?php echo $Lang?>'">		
		<input type="button" value="类别管理" onClick="javascript:location.href='ProductColumnManage.php?Lang=<?php echo $Lang?>'">		
	</td>	
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form id="form1" name="form1" method="post" action="ProductAdd.php?Lang=<?php echo $Lang?>" enctype="multipart/form-data" onSubmit="return FormCheck()">
  <tr class="odd">
    <td colspan="3" align="center" class="Main_Title">添加产品<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td align="right">选择类别：</td>
<td>
<select name="ProductRela" id="ProductRela">
<option selected="selected" value="">==请选择产品类别==</option>
<?php
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ) {
	Html($Rs[$i]);
	for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈┈';} //加与栏目级数相同的空格
	$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级栏目前不加空格符
	echo '<option value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	unset($Spaces);
}
unset($Rs,$i,$x);
?>  		
</select>
<span class="red">*</span></td>
    <td><a href="ProductColumnManage.php?Lang=<?php echo $Lang?>"><font color="#0000FF">点击添加产品类别</font></a></td>
  </tr>
  <tr class="odd">
    <td align="right">产品名称：</td>
    <td><input name="ProductName" type="text" class="input2" id="ProductName" maxlength="100" />
<?php
if($ConfigProductNameColor == 1){
	if(stripos($_SERVER["HTTP_USER_AGENT"],'MSIE')){ //检测客户端是否为IE浏览器
		echo '<input id="SelectColor" title="选择字体颜色" style="height:13px; width:13px; background-color:#ccc;" readonly="readonly" onClick="returnColor()">' . "\n";
		$DelColor = '<a href="javascript:" title="点击清除颜色" onClick="DelColor()"><img src="../images/check_error.gif" width="13" height="13" border="0" /></a>';
	} else {
		echo '<Select Name="SelectColor" id="SelectColor" OnChange="ProductName.style.color=this.value; ProductNameColor.value=this.value; this.style.backgroundColor=this.value;">
		<Option value="" Selected="Selected">选择字体颜色</Option>';
		include_once('../config/colorarray.php');
		foreach ($ColorArray as $key => $value){
			echo '<option value="' . $value . '" style="background:' . $value . '"></option>' . "\n";
		}
		echo '</Select>';
		unset($ColorArray,$key,$value);
	}
	echo ' <Input Name="ProductNameColor" type="text" id="ProductNameColor" value="" size="8" readonly="true" style="color:#999999;" /> ' . "\n";
	echo $DelColor;
}
?>
</td>
    <td><?php if($ConfigProductNameColor == 1) echo '可选择前台显示的产品名称字体颜色';?></td>
  </tr>
<?php if($ConfigProductBrand == 1){?>
  <tr class="odd">
    <td align="right">产品品牌：</td>
    <td><input name="ProductBrand" type="text" class="input2" id="ProductBrand" maxlength="30" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductModel == 1){?>
  <tr class="odd">
    <td align="right">产品型号：</td>
    <td><input name="ProductModel" type="text" class="input2" id="ProductModel" maxlength="30" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductCoding == 1){?>
  <tr class="odd">
    <td align="right">产品编码：</td>
    <td>
    <input name="ProductCoding" type="text" class="input2" id="ProductCoding" maxlength="30" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductSpeci == 1){?>
  <tr class="odd">
    <td align="right">产品规格：</td>
    <td><input name="ProductSpeci" type="text" class="input2" id="ProductSpeci" maxlength="30" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductColor == 1){?>
  <tr class="odd">
    <td align="right">产品颜色：</td>
    <td><input name="ProductColor" type="text" class="input2" id="ProductColor" maxlength="30" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductPrice == 1){?>
  <tr class="odd">
    <td align="right">价　　格：</td>
    <td><input name="ProductPrice" type="text" class="input2" id="ProductPrice" maxlength="30" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductPhoto1 == 1){?>
  <tr class="odd">
    <td align="right">产品图片(小)：</td>
    <td><input name="ProductPhoto1" id="ProductPhoto1" type="file" size="35" /></td>
    <td>图片上传大小限制：<font class="Igreen"><?php echo $ps['upload']['max_pics_size'];?></font> KB</td>
  </tr>
<?php } if($ConfigProductPhoto2 == 1){?>
  <tr class="odd">
    <td align="right">产品图片(大)：</td>
    <td><input name="ProductPhoto2" type="file" size="35" /></td>
    <td>图片上传大小限制：<font class="Igreen"><?php echo $ps['upload']['max_pics_size'];?></font> KB</td>
  </tr>
<?php } if($ConfigProductKeyWord == 1){?>
  <tr class="odd">
    <td align="right">关 键 字：</td>
    <td><input name="ProductKeyWord" type="text" class="input2" id="ProductKeyWord" /></td>
    <td>将被用来作为SEO优化关键词及Tag关键词，用英文逗号隔开，<br />留空时将采用"网站基本设置"中的搜索关键字作为SEO关键词</td>
  </tr>
<?php }

//自定义字段
foreach ($product_field as $i => $n){
	if($n[2] == 'TEXT' || $n[2] == 'MEDIUMTEXT' || $n[2] == 'LONGTEXT'){
		$input = "<textarea name=\"{$n[0]}\" style=\"width:300px; height:120px;\"></textarea>";	
	} else {
		$input = "<input name=\"{$n[0]}\" type=\"text\" class=\"input2\" maxlength=\"50\" />";
	}
	echo "<tr class=\"odd\">
    <td align=\"right\">{$n[1]}：</td>
    <td>{$input}</td>
    <td>自定义字段（类型：{$n[2]}）</td>
	</tr>";
}
//End

if($ConfigProductSummary == 1){?>
  <tr class="odd">
    <td align="right">简要描述：</td>
    <td><textarea name="ProductSummary" id="ProductSummary" style="width:300px; height:120px;"></textarea>
      <span class="red">*</span></td>
    <td>将被用来作为SEO优化描述字符，留空时将从详细介绍中截取部分字符</td>
  </tr>
<?php } if($ConfigProductContent == 1){?>
  <tr class="odd">
    <td align="right">详细介绍：</td>
    <td colspan="2"><textarea id="ProductContent" name="ProductContent" rows="10" cols="80"></textarea></td>
    </tr>
<?php } if($ConfigProductSecrecy == 1){?>
  <tr class="odd">
    <td align="right">查看权限：</td>
    <td>
<select name="ProductSecrecy" id="ProductSecrecy">
	<option value="0">完全公开</option>
<?php foreach ($UserLevel as $i => $value){echo '<option value="' . $value[1] . '">' . $value[0] . '</option>';} ?>
</select>
</td>
    <td>对该产品的查看权限进行设置</td>
  </tr>
<?php } if($ConfigProductAudit == 1){?>
  <tr class="odd">
    <td align="right">通过审核：</td>
    <td><input name="ProductAudit" type="radio" id="radio3" value="1" checked="checked" />
      是
      <input type="radio" name="ProductAudit" id="radio4" value="0" />
      否</td>
    <td>未通过审核的产品将不在任何页面中显示</td>
  </tr>
<?php } if($ConfigProductRecommended == 1){?>
  <tr class="odd">
    <td align="right">推荐产品：</td>
    <td><input name="ProductRecommended" type="radio" id="radio5" value="1" />
      是
      <input name="ProductRecommended" type="radio" id="radio6" value="0" checked="checked" />
      否</td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductNew == 1){?>
  <tr class="odd">
    <td align="right">新 产 品：</td>
    <td><input name="ProductNew" type="radio" id="radio5" value="1" />
      是
      <input name="ProductNew" type="radio" id="radio6" value="0" checked="checked" />
      否</td>
    <td>一般指最新推出、最新开发的产品</td>
  </tr>
<?php } if($ConfigProductClick == 1){?>
  <tr class="odd">
    <td align="right">点击次数：</td>
    <td><input name="ProductClick" type="text" id="ProductClick" value="<?php echo rand(0,500);?>" size="6" maxlength="6" /></td>
    <td>不建议修改</td>
  </tr>
<?php } if($ConfigProductSort == 1){?>
  <tr class="odd">
    <td align="right">排　　序：</td>
    <td><input name="ProductSort" type="text" id="ProductSort" value="0" size="6" maxlength="6" /></td>
    <td>值越大越靠前(不指定将按最新发表排序)</td>
  </tr>
<?php } if($ConfigProductPublished == 1){?>
  <tr class="odd">
    <td align="right">添 加 人：</td>
    <td><input name="ProductPublished" type="text" class="input2" id="ProductPublished" value="<?php echo $_SESSION['UserName']?>" maxlength="20" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($ConfigProductTime == 1){?>
  <tr class="odd">
    <td align="right">添加时间：</td>
    <td><input name="ProductTime" type="text" disabled="disabled" id="ProductTime" value="<?php echo date('Y-m-d H:i:s')?>" readonly="true" /></td>
    <td>&nbsp;</td>
  </tr>
<?php } if($WebStaticHTML == 1){?>
  <tr class="odd">
  	<td align="right">静态文件：</td>
  	<td><input name="isHTML" type="checkbox" id="isHTML" value="yes" />生成HTML</td>
  	<td>添加后将同时生成与该产品相关的所有静态页面</td>
  	</tr>
<?php }?>	
  <tr class="odd">
    <td align="right"><input name="Action" type="hidden" id="Action" value="Add" /></td>
    <td colspan="2"><input type="submit" name="button" id="button" value="提 交" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="button2" id="button2" value="重 置" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="button" name="backx" value="返 回" class="submit" onclick="history.back(-1)"></td>
    </tr>
  </form>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
		注：1、在系统高级参数设定中可以删除不必要的产品选项或开通更多的产品功能；
		</td>
	</tr>
</table>   
</body>
</html>
